﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.SqlClient;

namespace SoundServant
{
    /// <summary>
    /// Interaction logic for LoadWindow.xaml
    /// </summary>
    partial class SSMessageBox : SSWindow
    {
        private SSMessageBoxResult result = SSMessageBoxResult.Null;
        private SSMessageBoxType type;

        public SSMessageBox(string caption, string message, SSMessageBoxType _type)
        {
            InitializeComponent();
            type = _type;

            CaptionLabel.Content = caption;
            this.Title = caption;
            MessageTextBlock.Text = message;
            switch (type)
            {
                case SSMessageBoxType.Ok:
                    OkButton.Visibility = Visibility.Visible;
                    OkButton.Focus();
                    break;
                case SSMessageBoxType.YesNo:
                    YesNoGrid.Visibility = Visibility.Visible;
                    YesButton.Focus();
                    break;
                case SSMessageBoxType.ExclamationOk:
                    OkButton.Visibility = Visibility.Visible;
                    ExclamationMarkImage.Visibility = Visibility.Visible;
                    OkButton.Focus();
                    break;
                case SSMessageBoxType.ExcalamationYesNo:
                    ExclamationMarkImage.Visibility = Visibility.Visible;
                    YesNoGrid.Visibility = Visibility.Visible;
                    YesButton.Focus();
                    break;
                case SSMessageBoxType.None:
                    break;
                default:
                    break;
            }

        }

        public static SSMessageBoxResult Show(string _caption, string _message, SSMessageBoxType _type)
        {
            SSMessageBox msgBox = new SSMessageBox(_caption, _message, _type);
            return msgBox.ShowProxy();
        }
        public static SSMessageBoxResult Show(string _message)
        {
            SSMessageBox msgBox = new SSMessageBox(" ", _message, SSMessageBoxType.Ok);
            return msgBox.ShowProxy();
        }
        public static void ShowNonWait(string _message)
        {
            SSMessageBox msgBox = new SSMessageBox(" ", _message, SSMessageBoxType.Ok);
            msgBox.Topmost = true;
            msgBox.Show();
        }
        public static void ShowNonWait(string _caption, string _message)
        {
            SSMessageBox msgBox = new SSMessageBox(_caption, _message, SSMessageBoxType.Ok);
            msgBox.Topmost = true;
            msgBox.Show();
        }

        public static void ShowNonWait(string _caption, string _message, SSMessageBoxType _type)
        {
            SSMessageBox msgBox = new SSMessageBox(_caption, _message, _type);
            msgBox.Topmost = true;
            msgBox.Show();
        }

        public static SSMessageBoxResult Show(string _caption, string _message)
        {
            SSMessageBox msgBox = new SSMessageBox(_caption, _message, SSMessageBoxType.Ok);
            return msgBox.ShowProxy();
        }

        public SSMessageBoxResult ShowProxy()
        {
            ShowDialog();
            return result;
        }

        private void YesButton_Click(object sender, RoutedEventArgs e)
        {
            result = SSMessageBoxResult.Yes;
            this.Closing -= new System.ComponentModel.CancelEventHandler(Window_Closing);
            this.Close();
        }

        private void NoButton_Click(object sender, RoutedEventArgs e)
        {
            result = SSMessageBoxResult.No;
            this.Closing -= new System.ComponentModel.CancelEventHandler(Window_Closing);
            this.Close();
        }

        private void OkButton_Click(object sender, RoutedEventArgs e)
        {
            result = SSMessageBoxResult.Ok;
            this.Closing -= new System.ComponentModel.CancelEventHandler(Window_Closing);
            this.Close();
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;
        }
    }
}
